﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;

namespace HCMServices.DAO
{
    /// <summary>
    /// This class work with database
    /// </summary>
    public class DataHelper
    {
        /// <summary>
        /// This function move database to isolated storage  
        /// </summary>
        public static void MoveReferenceDatabase()
        {
            IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

            using (Stream input = Application.GetResourceStream(new Uri("DAO\\Database.sdf", UriKind.Relative)).Stream)
            {
                using (IsolatedStorageFileStream output = iso.CreateFile("Database.sdf"))
                {
                    byte[] readBuffer = new byte[4096];
                    int bytesRead = -1;

                    while ((bytesRead = input.Read(readBuffer, 0, readBuffer.Length)) > 0)
                    {
                        output.Write(readBuffer, 0, bytesRead);
                    }
                }
            }
        }
    }
}